<template>
    <div class="app-container">
        <div style="background-color: #fff;" class="border-radius">
            <div style="height: 7px;">

            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="300px" label-position="right">

                <div class="div-title" style="border-radius: 4px">
                    <span>预约规则设置</span>
                </div>
                <div>
                    <el-form-item label="用户提前" prop="cancelHour">
                        <el-input placeholder="请输入" v-model="form.cancelHour"  @input="form.cancelHour=form.cancelHour.replace(/^(0+)|[^\d]+/g, '')"  style="width: 300px;">
                            <template slot="append">小时</template>
                        </el-input>
                        可以取消预约单
                    </el-form-item>


                    <el-form-item label="用户提前" prop="updateHour" >
                        <el-input placeholder="请输入" v-model="form.updateHour"  @input="form.updateHour=form.updateHour.replace(/^(0+)|[^\d]+/g, '')"   style="width: 300px;">
                            <template slot="append">小时</template>
                        </el-input>
                        可以修改预约单
                    </el-form-item>


                    <el-form-item label="超时取消预约扣除" prop="cancelPunish" >
                        <el-input placeholder="请输入" v-model="form.cancelPunish"  @input="form.cancelPunish=form.cancelPunish.replace(/^(0+)|[^\d]+/g, '')"  style="width: 300px;">
                            <template slot="append">菠萝派</template>
                        </el-input>
                    </el-form-item>

                    <el-form-item label="用户爽约扣除" prop="noshowPunish" >
                        <el-input placeholder="请输入" v-model="form.noshowPunish"  @input="form.noshowPunish=form.noshowPunish.replace(/^(0+)|[^\d]+/g, '')"  style="width: 300px;">
                            <template slot="append">菠萝派</template>
                        </el-input>
                    </el-form-item>
                </div>
                <div class="div-title">
                    <span>其他设置</span>
                </div>
                <div>
                    <el-form-item label="完成服务奖励" prop="finishReward" >
                        <el-input placeholder="请输入" v-model="form.finishReward"  @input="form.finishReward=form.finishReward.replace(/^(0+)|[^\d]+/g, '')" style="width: 300px;">
                            <template slot="append">菠萝派</template>
                        </el-input>
                    </el-form-item>

                    <el-form-item label="完成评价奖励" prop="appraiseReward" >
                        <el-input placeholder="请输入" v-model="form.appraiseReward"   @input="form.appraiseReward=form.appraiseReward.replace(/^(0+)|[^\d]+/g, '')" style="width: 300px;">
                            <template slot="append">菠萝派</template>
                        </el-input>
                    </el-form-item>




                    <el-form-item label="预约信息提醒设置" prop="tip" >
                        <el-input type="textarea" placeholder="请输入" v-model="form.tip" style="width: 500px;" maxlength="255"
                            show-word-limit></el-input>
                    </el-form-item>


                    <el-button type="primary" @click="submitForm"
                        style="margin-top: 20px;    margin-bottom: 20px;margin-left: 45%;">保存</el-button>


                </div>

            </el-form>
        </div>
    </div>
</template>
<script>
import {
    get,
    save

}
    from "@/api/customer/set";

export default {
    components: {
    },
    data() {
        return {
            dynamicTags: [],
            inputVisible: false,
            inputValue: '',
            open: false,
            openOrder: false,
            checkboxOne: false,
            checkboxTwo: false,
            checkboxThree: false,
            checkboxFour: false,
            checkboxFive: false,
            checkboxSix: false,
            oldform: {},
            openOne: false,
            nrolling: [],
            goodsLikeList: [],
            form: {
                customerserviceGoodsConfigMap: {
                    default: 0
                },
                customerserviceOrderConfigMap: {
                    default: 0
                },
                commentProductMap: {
                    rate: ""
                },
                commentServiceMap: {
                    rate: ""
                },
                commentLogisticsMap: {
                    rate: ""
                },
                goodsSaleNumberMap: {
                    number: ""
                },
                orderPayment: null,
                info: {
                    platformName: ""
                }
            },
            rules: {
                platformName: [{
                    required: true,
                    message: "店铺不能为空",
                    trigger: "blur"
                }],
                region: [{
                    required: true,
                    message: "店铺地址不能为空",
                    trigger: "blur"
                }],
                mainCategory: [{
                    required: true,
                    message: "主营品类不能为空",
                    trigger: "blur"
                }],
                platformEmail: [{
                    type: "email",
                    message: "'请输入正确的邮箱地址",
                    trigger: ["blur", "change"]
                }],
                servePhone: [{
                    required: true,
                    pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                    message: "请输入正确的手机号码",
                    trigger: ["blur", "change"]
                }]
            },
            selectOptions: [],
            codeOptions: [],
            options: [],
            region: [],
        };
    },
    created() {
        this.getList();
        // getPayLevel().then(response => {
        //     this.selectOptions = response;
        // });
        // this.getDicts("platform_trade_code").then(response => {
        //     this.codeOptions = response.data;
        // });
        // // 产地
        // getRegion().then((response) => {
        //     this.options = response.data;
        // });
    },
    methods: {
        vs(value) {
            console.log(value)
        },
        handleClose(tag) {
            this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
        },

        showInput() {
            this.inputVisible = true;
            this.$nextTick(_ => {
                this.$refs.saveTagInput.$refs.input.focus();
            });
        },

        handleInputConfirm() {
            let inputValue = this.inputValue;
            if (inputValue) {
                if (inputValue.indexOf(",") > -1) {
                    this.$message.error("不能包含逗号");
                    return false;
                }
                this.dynamicTags.push(inputValue);
            }
            this.inputVisible = false;
            this.inputValue = '';
        },
        kefu() {
            this.open = true;
        },
        kefuOrder() {
            this.openOrder = true;
        },
        kefuOne() {
            this.openOne = true;
        },
        getList() {
            // let arr = ['123','123']
            // console.log(arr.join(','))
            get().then(response => {
                this.oldform = response.oldData;
                if(response.data != undefined){
                    this.form = response.data;

                    let dx = this.form;
                //this.createCheckBox(dx);
                // if (dx.hotSearchs) {
                //     this.dynamicTags = dx.hotSearchs;
                // }
                }

            })
        },
        submitForm() {
            let dx = this.form;

            this.$refs["form"].validate(valid => {
                save(this.form).then(response => {
                    this.$message.success("修改成功!")
                    this.get();
                })

            });
        },
        changeAB(value) {
            if (value == 1) {
                this.form.customerserviceGoodsConfigMap.default = this.oldform.customerserviceGoodsConfigMap.default;
                if (this.oldform.customerserviceGoods == "1") {
                    this.checkboxOne = true;
                    this.form.customerserviceGoodsConfigMap.label = this.oldform.customerserviceGoodsConfigMap.label;
                } else {
                    this.checkboxOne = false;
                    this.changeA(0);
                }
                this.form.customerserviceOrderConfigMap.default = this.oldform.customerserviceOrderConfigMap.default;
                if (this.oldform.customerserviceOrder == "1") {
                    this.checkboxTwo = true;
                    this.form.customerserviceOrderConfigMap.label = this.oldform.customerserviceOrderConfigMap.label;
                } else {
                    this.checkboxTwo = false;
                    this.changeB(0);
                }
            }
        },
        changeA(value) {
            if (value == 0) {
                this.form.customerserviceGoodsConfigMap.label = "";
            }
        },
        changeB(value) {
            if (value == 0) {
                this.form.customerserviceOrderConfigMap.label = "";
            }
        },
        changeC(value) {
            if (value == 0) {
                this.form.goodsSaleNumberMap.number = "";
                this.checkboxSix = false;
            }
        },
        checkValue(dx) {
            // 数据校验

            if (dx.isCustomerservice == "1") {
                if (dx.customerserviceGoods == "1") {
                    if (dx.customerserviceGoodsConfigMap.default == "1") {
                        if (dx.customerserviceGoodsConfigMap.label == "") {
                            this.$message.error("请填写自定义名称！")
                            return 1;
                        }
                    }
                }
                if (dx.customerserviceOrder == "1") {
                    if (dx.customerserviceOrderConfigMap.default == "1") {
                        if (dx.customerserviceOrderConfigMap.label == "") {
                            this.$message.error("请填写自定义名称！")
                            return 1;
                        }
                    }
                }
            }
            if (dx.isVip == "1") {
                if (dx.vipUid == "") {
                    this.$message.error("请选择VIP！")
                    return 1;
                }
            }
            if (dx.platformLogUrl == "") {
                this.$message.error("请上传店铺logo！")
                return 1;
            }

            if (dx.isGoodsComment == "1") {
                if (dx.commentServiceMap.show == "1") {
                    if (dx.commentServiceMap.rate == "") {
                        this.$message.error("请填写服务评星！")
                        return 1;
                    }
                }
                if (dx.commentProductMap.show == "1") {
                    if (dx.commentProductMap.rate == "") {
                        this.$message.error("请填写商品评星！")
                        return 1;
                    }
                }
                if (dx.commentLogisticsMap.show == "1") {
                    if (dx.commentLogisticsMap.rate == "") {
                        this.$message.error("请填写物流评星！")
                        return 1;
                    }
                }
            }
            if (dx.waitOrderPayment == "") {
                this.$message.error("请填写待付款自动取消时间！")
                return 1;
            }
            if (dx.orderPayment == "") {
                this.$message.error("请填写付款可手动取消时间！")
                return 1;
            }
            if (dx.orderAddress == "") {
                this.$message.error("请填写付款后可手动修改地址的时间！")
                return 1;
            }
            if (dx.orderMoney == "") {
                this.$message.error("请填写收货后，分润的解冻时间！")
                return 1;
            }
            if (dx.goodsIntegral == "") {
                this.$message.error("请填写1元等于多少积分！")
                return 1;
            }
            return 0;
        },
        createCheckBox(dx) {
            if (dx.customerserviceGoods == "1") {
                this.checkboxOne = true;
            }
            if (dx.customerserviceOrder == "1") {
                this.checkboxTwo = true;
            }
            this.nrolling = [];
            if (dx.isSuspensionrolling == "1") {
                if (dx.suspensionrollingBuy == "1") {
                    this.nrolling.push("1")
                } else {
                    //this.nrolling.push("0")
                }
                if (dx.suspensionrollingComment == "1") {
                    this.nrolling.push("2")
                } else {
                    //this.nrolling.push("0")
                }
                if (dx.suspensionrollingCollection == "1") {
                    this.nrolling.push("3")
                } else {
                    //this.nrolling.push("0")
                }
                if (dx.suspensionrollingView == "1") {
                    this.nrolling.push("4")
                } else {
                    //this.nrolling.push("0")
                }
            }
            if (dx.commentServiceMap.show == "1") {
                this.checkboxThree = true;
            }
            if (dx.commentProductMap.show == "1") {
                this.checkboxFour = true;
            }
            if (dx.commentLogisticsMap.show == "1") {
                this.checkboxFive = true;
            }
            if (dx.goodsLikeGoods == "1") {
                this.goodsLikeList.push("1")
            } else {
                this.goodsLikeList.push("0")
            }
            if (dx.goodsLikeBuy == "1") {
                this.goodsLikeList.push("2")
            } else {
                this.goodsLikeList.push("0")
            }
            if (dx.goodsLikeCart == "1") {
                this.goodsLikeList.push("3")
            } else {
                this.goodsLikeList.push("0")
            }
            if (dx.goodsLikeOrderDetail == "1") {
                this.goodsLikeList.push("4")
            } else {
                this.goodsLikeList.push("0")
            }
            if (dx.goodsLikeOrderDetails == "1") {
                this.goodsLikeList.push("5")
            } else {
                this.goodsLikeList.push("0")
            }
            if (dx.goodsLikeRefund == "1") {
                this.goodsLikeList.push("6")
            } else {
                this.goodsLikeList.push("0")
            }
            if (dx.isGoodsSaleNumber == 1) {
                checkboxSix = true;
            }

        }
    }
};
</script>

<style scoped>
.el-tag+.el-tag {
    margin-left: 10px;
}

.button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
}

.input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
}

.block {
    padding: 30px 0;
    text-align: center;
    display: inline-block;
    vertical-align: top;
}

.app-container {
    background-color: #F7F8FA;
    padding: 20px;
}

.font-normal1 {
    font-size: 12px;
    color: #84868a;
    margin-top: -5px;
}

.font-normal {
    font-size: 12px;
    color: #84868a;
    margin-top: -6px;
}

.div-title {
    background-color: rgb(242, 246, 252);
    margin: 15px;
    padding: 10px 10px 10px 10px;
    font-weight: 500;
}

.dw {
    z-index: 2000;
    border: 1px;
    position: fixed;
    bottom: 0px;
    background-color: #f7f8fa;
    width: 100%;
    height: 55px;
}
</style>
